package Month09.day0927;

public class TestDataType {
   String name;
   int age;

    public TestDataType(String name, int data) {
        this.name = name;
        this.age = data;
    }
    public String toString(){
        return "[" + this.name + "," + this.age + "]";
    }

    public boolean equals(Object obj){
        if(this == obj) {//如果两个对象地址相同，那就没有比较的意义了
            return true;
        }
        if(!(obj instanceof TestDataType)){//确保传入的类是TestDataType,如果不是这个类，就会出现类型转换异常。
            return false;
        }

        TestDataType test = (TestDataType) obj;//向下转型为当前类
        return this.name.equals(test.name) && this.age == test.age;
    }
    public static void main(String[] args) {
        TestDataType test1 = new TestDataType("光头强",25);
        TestDataType test2 = new TestDataType("光头强",25);
        System.out.println(test1.equals(test2));
        System.out.println(test1.equals("巴拉啦能量"));
        System.out.println(test1.equals(null));
    }
}
 /* int a = 10;
        long b = 10;
        double c1 = 10.1;
        double c2 = 10.0;
        System.out.println(a == b);
        System.out.println(a == c1);
        System.out.println(a == c2);*/